package com.bestcem.xm.om.dao.impl;

import cn.hutool.core.lang.ObjectId;
import com.bestcem.xm.om.dao.PlatformDao;
import com.bestcem.xm.om.dao.mapper.PlatformMapper;
import com.bestcem.xm.om.dao.param.PlatformParamDO;
import com.bestcem.xm.om.entity.OmPlatform;
import com.bestcem.xm.om.enums.PlatformStatusEnum;
import com.bestcem.xm.om.grpc.service.param.OmPlatformParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;

/**
 * @author zhangfeng <feng.zhang@idiaoyan.com>
 * @version v1.0
 * @date 2022/3/22 14:50
 */
@Slf4j
@Repository
public class PlatformDaoImpl implements PlatformDao {
    @Resource
    private PlatformMapper platformMapper;

    @Override
    public List<OmPlatform> listPlatform(PlatformParamDO param) {
        return platformMapper.listByParam(param);
    }

    @Override
    public Integer countPlatform(PlatformParamDO platformParamDO) {
        return platformMapper.countByParam(platformParamDO);
    }

    @Override
    public OmPlatform findById(String id) {
        return platformMapper.findById(id);
    }

    @Override
    public OmPlatform findOneByOrgId(String orgId) {
        return platformMapper.findOneByOrgId(orgId);
    }

    @Override
    public OmPlatform findOneByPlatformCode(String platformCode) {
        return platformMapper.findOneByPlatformCode(platformCode);
    }

    @Override
    public String insert(OmPlatform omPlatform) {
        omPlatform.setId(ObjectId.next());
        omPlatform.setCreateTime(LocalDateTime.now());
        omPlatform.setUpdateTime(LocalDateTime.now());
        platformMapper.insert(omPlatform);
        return omPlatform.getId();
    }

    @Override
    public void update(OmPlatform omPlatform) {
        platformMapper.update(omPlatform);
    }

    @Override
    public List<OmPlatform> listByPlatformParam(OmPlatformParam param) {
        return platformMapper.listByPlatformParam(param);
    }

    @Override
    public List<OmPlatform> listByStatus(PlatformStatusEnum status) {
        return platformMapper.listByStatus(status.getIndex());
    }

    @Override
    public List<OmPlatform> listByCodes(Collection<String> platformCodes) {
        return platformMapper.listByCodes(platformCodes);
    }
}
